import { request , request1} from "../network/request"



export default{
  setGoodsList(s,v){
    request({
      url:'/shop/goods/list/v2',
      method:'post',
      data:s.state.goods
    }).then(res=>{
      s.commit("SET_TOTAL",res.data.data.totalRow)
      res.data.data.result.forEach(el=>{
        if(el.status==0){
          el.shangjia=true
          // this.$set(el,'shangjia',true)
        }else if(el.status==1){
          el.shangjia=false
          // this.$set(el,'shangjia',false)
        }
        if(el.recommendStatus==0){
          el.tuijian=false
          // this.$set(el,'tuijian',false)
        }else if(el.recommendStatus==1){
          el.tuijian=true
          // this.$set(el,'tuijian',true)
        }
      })
      s.commit("SET_GOODS_LIST",res.data.data.result)
    })
  },
  setGoods({commit},v){
    commit("SET_GOODS",v)
  },
  setTotal({commit},v){
    commit("SET_TOTAL",v)
  },
  changeGoodsInfo(store,v){
    return new Promise((rev,rej)=>{
      request1({
        url:'/user/apiExtShopGoods/modify/status',
        method:'post',
        data:v
      }).then(res=>{
        rev(res)
      }).catch(err=>{
        rej(err)
      })
    })
  },

  changeTuiJian(store,v){
    return new Promise((rev,rej)=>{
      request1({
        url:'/user/apiExtShopGoods/modify/recommendStatus',
        method:'post',
        data:v
      }).then(res=>{
        rev(res)
      }).catch(err=>{
        rej(err)
      })
    })
  },
  setTitleList({commit},v){
    commit('SET_TITLE_LIST',v)
  },
  setYonghuList(s,v){
    request1({
      url:'/user/apiExtUser/list',
      method:'post',
      data:{
        page:'',
        pageSize:'',
      }
    }).then(res=>{
      console.log(res.data.data.result);
      s.commit('SET_TOTAL',res.data.data.totalRow)
      s.commit('SET_YONGHU_LIST',this.yonghuList=res.data.data.result)
    })
  },
}